﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KBVault.Web.Infrastructure;
using KBVault.DAL.Repository;
using KBVault.DAL.Entities;
//using iTextSharp.text;
//using iTextSharp.text.html.simpleparser;
//using iTextSharp.text.pdf;
using System.IO;

namespace KBVault.Web.Public
{
    public partial class Export : KBVaultPublicPage
    {
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            /*
             * Not used anymore, but this piece will remain here as a memory :)
            try
            {
                Article a = ArticleRepository.Get(ActiveArticleId);
                Response.ContentType = "application/pdf";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.AddHeader("content-disposition", String.Format("attachment;filename=KBVaultArticle-{0}.pdf",a.Id));
                var pdfDocument = new Document(PageSize.A4);
                string path = Server.MapPath("/Uploads");
                Dictionary<string, object> providers = new Dictionary<string, object>();
                providers.Add(HTMLWorker.IMG_PROVIDER, new TextSharpImageThing(pdfDocument, Server.MapPath("/")));
                PdfWriter.GetInstance(pdfDocument, Response.OutputStream);// new FileStream(path + "/Doc1.pdf", FileMode.Create));
                HTMLWorker htmlparser = new HTMLWorker(pdfDocument);
                pdfDocument.Open();
                string fontpath = Server.MapPath("/assets/fonts/");
                BaseFont customfont = BaseFont.CreateFont(fontpath + "arialroundbold.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
                Font font = new Font(customfont, 16);
                pdfDocument.Add(new Paragraph(a.Title, font));
                pdfDocument.Add(new Paragraph(" ", font));
                List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(Server.HtmlDecode(a.Content)), null, providers);
                for (int k = 0; k < htmlarraylist.Count; k++)
                {
                    pdfDocument.Add((IElement)htmlarraylist[k]);
                }
                pdfDocument.Close();
                Response.Write(pdfDocument);
                Response.End();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                ShowExceptionError();
            }
             * */
        }
    }
}